import React, { Component } from 'react';
import store, {actions} from '../store/index'

class Redux extends Component {
  constructor() {
    super();
    this.state = {

    }
  }
  componentDidMount() {
    console.log(111, store.getState());
    this.setState(store.getState().user.info);
    this.un = store.subscribe(()=>{
      this.setState(store.getState().user.info);
    })
  }
  break() {
    // store.dispatch(actions.changeAge(30));
    console.log(store.getState());
  }
  oldMan() {
    // store.dispatch(actions.changeName('Old Tom'))
  }
  componentWillUnmount() {
    this.un()
  }
  render() {
    return (
      <div>
        <p>redux的使用</p>
        <p>age: {this.state.age}</p>
        <button onClick={()=>this.break()}>快进到退休</button>
        <p>name: {this.state.name}</p>
        <button onClick={()=>this.oldMan()}>快进到老头</button>
      </div>
    );
  }
}

export default Redux;
